package com.problem.leetcode;

/**
 * @author didi
 * @DESCRIPTION problem788
 * @create 2018-04-13 下午8:14
 **/
public class Problem788 {


    public int rotatedDigits(int N) {
        int tmp    = 0;
        int result = 0;
        for (int index = 1; index <= N; ++index) {
            if (isGoodNum(index)) {
                ++result;
            }
        }
        return result;
    }

    private boolean isGoodNum(int number) {
        String        value   = String.valueOf(number);
        char[]        values  = value.toCharArray();
        StringBuilder builder = new StringBuilder();

        for (int index = 0; index < value.length(); ++index) {
            if (values[index] == '3' || values[index] == '7' || values[index] == '4') {
                return false;
            }

            if (values[index] == '1' || values[index] == '0' || values[index] == '8') {
                continue;
            }

            switch (values[index]) {
                case '2':
                    values[index] = '5';
                    break;
                case '5':
                    values[index] = '2';

                    break;
                case '6':
                    values[index] = '9';

                    break;
                case '9':
                    values[index] = '6';

                    break;
                default:
                    break;
            }
        }
        if(Integer.parseInt(String.valueOf(values)) == number) {
            return false;
        }
        return true;
    }


    public static void main(String[] args) {
        int result = new Problem788().rotatedDigits(847);
        System.out.println(result);
    }

}
